package com.david.func_test.widget

import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.FOCUS_BLOCK_DESCENDANTS
import android.widget.Adapter
import android.widget.TextView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

class TabListAdapter: RecyclerView.Adapter<TabListAdapter.MyHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyHolder {
        return if (viewType == 0) {
            val list = RecyclerView(parent.context)
            list.layoutManager = LinearLayoutManager(parent.context, LinearLayoutManager.HORIZONTAL, false)
            list.descendantFocusability = FOCUS_BLOCK_DESCENDANTS
            list.setPadding(0, 20, 0, 20)
            list.adapter = object : RecyclerView.Adapter<MyHolder>(){
                override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyHolder {
                    val title = TextView(parent.context)
                    title.setPadding(20, 20, 20, 20)
                    title.text = "title"
                    return MyHolder(title)
                }

                override fun onBindViewHolder(holder: MyHolder, position: Int) {
                }

                override fun getItemCount(): Int {
                    return 20
                }

            }
            MyHolder(list)
        } else {
            val title = TextView(parent.context)
            title.setPadding(0, 20, 0, 20)
            title.text = "title"
            MyHolder(title)
        }
    }

    override fun onBindViewHolder(holder: MyHolder, position: Int) {
    }

    override fun getItemCount(): Int {
        return 30
    }

    override fun getItemViewType(position: Int): Int {
        return if (position == 0) {
            0
        } else {
            1
        }
    }



    inner class MyHolder(itemView: View): RecyclerView.ViewHolder(itemView) {

    }
}